# initList = [
#     {
#         'name': '木舟1',
#         'age': '25'
#     },
#     {
#         'name': '木舟2',
#         'age': '26'
#     },
#     {
#         'name': '木舟3',
#         'age': '27'
#     },
# ]
#
# # newList = [
# #     x['age']
# #     for x in initList
# # ]
# #
# # print(newList)
#
# newList = []
# for x in initList:
#     newList.append(x['name'])
# print(newList)

# 运行结果
"""
['木舟1', '木舟2', '木舟3']
"""

# lst = [1, 2, 3, 4]
#
# newLst = [
#     x
#     for x in lst
# ]
# print(newLst)


initList = [
    {
        'name': '木舟1',
        'age': 25
    },
    {
        'name': '木舟2',
        'age': 26
    },
    {
        'name': '木舟3',
        'age': 27
    },
]

# newList = [x['name'] for x in initList if x['age'] > 25]
# newList = []
# for x in initList:
#     # if x['age'] > 25:
#     #     newList.append(x['name'])
#     x['age'] > 25 and newList.append(x['name'])

# print(newList)

# 运行结果
"""
['木舟2', '木舟3']
"""

from dis import dis

initList = [
    [
        {
            'name': '木舟1',
            'age': 25
        },
        {
            'name': '木舟2',
            'age': 26
        },
        {
            'name': '木舟3',
            'age': 27
        },

    ],
    [
        {
            'name': '木舟4',
            'age': 28
        },
        {
            'name': '木舟5',
            'age': 29
        },
        {
            'name': '木舟6',
            'age': 30
        },
    ],
    [
        {
            'name': '木舟7',
            'age': 31
        },
    ],
]

newList = [
    j
    for idx, innerList in enumerate(initList)
    if idx + 1 != len(initList)
    for j in innerList
    if j['age'] > 25 and j['age'] != 30
]

print(newList)

# 运行结果
"""
[{'name': '木舟2', 'age': 26}, {'name': '木舟3', 'age': 27}, {'name': '木舟4', 'age': 28}, {'name': '木舟5', 'age': 29}]
"""

initList = [
    ['age', 20],
    ['name', '木舟1'],
]

newDict = {
    i[0]: i[1]
    for i in initList
}

print(newDict)

# 运行结果
"""
{'age': 20, 'name': '木舟1'}
"""

# 生成器推导式

newGenerator = (i for i in initList)  # 就是把原来列表推导式的 [] 换成 ()
# 关于生成器和迭代器的知识，会专门有文章进行讲解